package com.sojson.project.pay.service.ali.impl;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sojson.base.impl.BaseOrder;
import com.sojson.constant.IpConfig;
import com.sojson.project.dao.OrderDepositDao;
import com.sojson.project.dao.TransferRecordDao;
import com.sojson.project.dao.UserCouponDao;
import com.sojson.project.entity.bo.PayResponse;
import com.sojson.project.pay.service.PayService;
import com.sojson.project.pay.service.ali.PayAliAppService;
import com.sojson.util.pay.ali.AliUtil;
import com.sojson.util.pay.ali.bean.AliResult;
import com.sojson.util.pay.ali.constant.AliConstant;

/**
 * 支付宝App支付Service实现类
 *
 * @author liu
 * @date 2021-03-24
 */
@Service
public class PayAliAppServiceImpl implements PayAliAppService {

    @Autowired
    private PayService payService;
    @Resource
    private UserCouponDao userCouponDao;
    @Resource
    private OrderDepositDao orderDepositDao;
    @Resource
    private TransferRecordDao transferRecordDao;

    /**
     * 商城购物车调起支付
     *
     * @param nos
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor = Throwable.class)
    public AliResult goodsShop(String[] nos) throws Exception {
        // 获取订单信息
        PayResponse goodsShop = payService.goodsShop(nos);

        // 是否是购物车支付
        if (goodsShop.getIsShop()) {
            return null;
        } else {
            return AliUtil.payApp(goodsShop.getOrder(), IpConfig.getUrl() + AliConstant.NOTIFY_URL_GOODS);
        }
    }

    /**
     * 诚意金调起支付
     *
     * @param orderId
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor = Throwable.class)
    public AliResult deposit(String orderId) throws Exception {
        // 获取订单信息
        BaseOrder deposit = payService.deposit(orderId);

        return AliUtil.payApp(deposit, IpConfig.getUrl() + AliConstant.NOTIFY_URL_ORDER_DEPOSIT);
    }

}